<?php


use Phinx\Seed\AbstractSeed;

class InitSeeder extends AbstractSeed
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * http://docs.phinx.org/en/latest/seeding.html
     */
    public function run()
    {
        /**
         * 添加 admin
         */
        $slat = md5('xx');
        $password = '123456';
        $user = [
            [
                'username'  => 'admin',
                'slat'      => $slat,
                'password'  => md5("${slat}${password}${slat}")
            ]
        ];
        $userTable = $this->table('user');
        $userTable->insert($user)->save();

        $row = $this->fetchRow('select id from user');
        $id = $row['id'];

        /**
         * https://www.sec-wiki.com/opml/index
         * https://www.solidot.org/index.rss
         */
        $resource = [
            [
                'type'      => 'rss',
                'name'      => 'chabug',
                'url'       => 'https://www.chabug.org/feed',
                'user_id'   => $id,
                'extinfo'   => '{"parse_mode":"html"}'
            ],[
                'type'      => 'rss',
                'name'      => 'bestwing',
                'url'       => 'https://bestwing.me/atom.xml',
                'user_id'   => $id,
                'extinfo'   => '{"parse_mode":"html"}'
            ],[
                'type'      => 'rss',
                'name'      => 'formsec',
                'url'       => 'https://blog.formsec.cn/atom.xml',
                'user_id'   => $id,
                'extinfo'   => '{"parse_mode":"html"}'
            ],[
                'type'      => 'rss',
                'name'      => 'nsfocus',
                'url'       => 'http://blog.nsfocus.net/feed/',
                'user_id'   => $id,
                'extinfo'   => '{"parse_mode":"html"}'
            ],[
                'type'      => 'rss',
                'name'      => 'youxia',
                'url'       => 'http://www.youxia.org/feed',
                'user_id'   => $id,
                'extinfo'   => '{"parse_mode":"html"}'
            ],[
                'type'      => 'rss',
                'name'      => 'redclub',
                'url'       => 'http://sec-redclub.com/index.php/feed/',
                'user_id'   => $id,
                'extinfo'   => '{"parse_mode":"html"}'
            ]
        ];
        $resourceTable = $this->table('resource');
        $resourceTable->insert($resource)->save();

        $destination1 = [
            'type'      => 'telegram',
            'name'      => 'NetSafeBot',
            'dest'      => '@webinfor',
            'extinfo'   => 'channel'
        ];
        $destination2 = [
            'type'      => 'telegram',
            'name'      => '天天飘红~',
            'dest'      => '-303225768',
            'extinfo'   => 'group'
        ];
        $destinationTable = $this->table('destination');
        $destinationTable->insert($destination1)->save();
        $destinationTable->insert($destination2)->save();
    }
}
